﻿using System;
using System.Xml;
using System.Configuration;

namespace Alex.Library.Log.Configuration
{
    public abstract class EnumContentElement<T> : ConfigurationElement where T : struct
    {
        /// <summary>
        /// 元素内容
        /// </summary>
        [ConfigurationProperty("data", IsRequired = true)]
        public T Value
        {
            get
            {
                return (T)this["data"];
            }
            set
            {
                this["data"] = value;
            }
        }

        /// <summary>
        /// 序列化内容到配置信息
        /// </summary>
        /// <param name="writer"></param>
        /// <param name="serializeCollectionKey"></param>
        /// <returns></returns>
        protected override bool SerializeElement(XmlWriter writer, bool serializeCollectionKey)
        {
            if (writer != null)
            {
                writer.WriteString(this.Value.ToString());
            }

            return true;
        }
    }
}
